/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SGFilterEditor.java
 *
 * Created on 2009-10-30, 18:31:40
 */
package mr.go.sgfilter.vis.app;

import java.awt.Color;
import java.awt.Dimension;
import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JSpinner;
import javax.swing.JSpinner.NumberEditor;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SpinnerNumberModel;
import javax.swing.border.LineBorder;
import org.jdesktop.application.Application;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;
import org.jdesktop.beansbinding.BeanProperty;
import org.jdesktop.beansbinding.Binding;
import org.jdesktop.beansbinding.BindingGroup;
import org.jdesktop.beansbinding.Bindings;
import org.jdesktop.beansbinding.ELProperty;

/**
 *
 * @author Rzeźnik
 */
public class SGFilterEditor extends javax.swing.JPanel {

    private final SGFilterBean bean;

    /** Creates new form SGFilterEditor */
    public SGFilterEditor() {
        this(null);
    }

    public SGFilterEditor(SGFilterBean bean) {
        this.bean = bean;
        initComponents();
    }

    public SGFilterBean getBean() {
        return bean;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new BindingGroup();
        JLabel polynomialDegreeLabel = new JLabel();
        polynomialDegreeSpinner = new JSpinner();
        JLabel nlLabel = new JLabel();
        nlSpinner = new JSpinner();
        JLabel nrLabel = new JLabel();
        nrSpinner = new JSpinner();
        ResourceMap resourceMap =
                Application.getInstance(mr.go.sgfilter.vis.app.Application.class).
                getContext().getResourceMap(SGFilterEditor.class);
        setBorder(BorderFactory.createTitledBorder(new LineBorder(new Color(0, 0, 0), 1, true), resourceMap.getString("SGFilterEditor.border.title"))); // NOI18N
        setName("SGFilterEditor"); // NOI18N
        setPreferredSize(new Dimension(470, 100));

        polynomialDegreeLabel.setLabelFor(polynomialDegreeSpinner);
        polynomialDegreeLabel.setText(resourceMap.getString("polynomialDegreeLabel.text")); // NOI18N
        polynomialDegreeLabel.setName("polynomialDegreeLabel"); // NOI18N

        polynomialDegreeSpinner.setModel(new SpinnerNumberModel(Integer.valueOf(2), Integer.valueOf(2), null, Integer.valueOf(1)));
        polynomialDegreeSpinner.setEditor(new NumberEditor(polynomialDegreeSpinner, ""));
        polynomialDegreeSpinner.setName("polynomialDegreeSpinner"); // NOI18N

        Binding binding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, this, ELProperty.create("${bean.degree}"), polynomialDegreeSpinner, BeanProperty.create("value"));
        bindingGroup.addBinding(binding);

        nlLabel.setLabelFor(nlSpinner);
        nlLabel.setText(resourceMap.getString("nlLabel.text")); // NOI18N
        nlLabel.setName("nlLabel"); // NOI18N

        nlSpinner.setModel(new SpinnerNumberModel());
        nlSpinner.setEditor(new NumberEditor(nlSpinner, ""));
        nlSpinner.setName("nlSpinner"); // NOI18N

        binding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, this, ELProperty.create("${bean.nl}"), nlSpinner, BeanProperty.create("value"));
        bindingGroup.addBinding(binding);

        nrLabel.setText(resourceMap.getString("nrLabel.text")); // NOI18N
        nrLabel.setName("nrLabel"); // NOI18N

        nrSpinner.setModel(new SpinnerNumberModel(Integer.valueOf(0), Integer.valueOf(0), null, Integer.valueOf(1)));
        nrSpinner.setEditor(new NumberEditor(nrSpinner, ""));
        nrSpinner.setName("nrSpinner"); // NOI18N

        binding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, this, ELProperty.create("${bean.nr}"), nrSpinner, BeanProperty.create("value"));
        bindingGroup.addBinding(binding);

        GroupLayout layout = new GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(polynomialDegreeLabel)
                        .addGap(18, 18, 18)
                        .addComponent(polynomialDegreeSpinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(nlLabel)
                        .addGap(18, 18, 18)
                        .addComponent(nlSpinner)))
                .addGap(18, 18, 18)
                .addComponent(nrLabel)
                .addGap(18, 18, 18)
                .addComponent(nrSpinner, GroupLayout.PREFERRED_SIZE, 48, GroupLayout.PREFERRED_SIZE)
                .addContainerGap(76, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(polynomialDegreeLabel)
                    .addComponent(polynomialDegreeSpinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(nlLabel)
                    .addComponent(nlSpinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addComponent(nrLabel)
                    .addComponent(nrSpinner, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private JSpinner nlSpinner;
    private JSpinner nrSpinner;
    private JSpinner polynomialDegreeSpinner;
    private BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}
